(require 'evil-leader)
(evil-leader/set-key
  "w" 'save-buffer
  "W" 'save-some-buffers
  "C" 'kill-buffer-and-window
  "c" 'kill-this-buffer
  "p" 'previous-error
  "n" 'next-error
  "g" 'magit-status
  "q" 'ido-kill-buffer
  "o" 'ido-find-file
  "b" 'ido-switch-buffer
  "e" 'eval-last-sexp
  "x" 'smex
  "m" 'woman
  "H" 'evil-window-left
  "L" 'evil-window-right
  "J" 'evil-window-down
  "K" 'evil-window-up
  "h" 'highlight-symbol-at-point
  "r" 'highlight-symbol-remove-all
  "?" 'describe-function
  "f" 'describe-current-function
  "v" 'describe-current-variable
  "0" 'delete-window
  "1" 'delete-other-windows
  "ss" 'cscope-find-this-symbol
  "sd" 'cscope-find-global-definition
  "sa" 'cscope-set-initial-directory
  "sb" 'cscope-display-buffer
  "sf" 'cscope-find-this-file
  "sc" 'cscope-find-functions-calling-this-function
  "sn" 'cscope-history-forward-line-current-result
  "sp" 'cscope-history-backward-line-current-result
  "sN" 'cscope-history-forward-file-current-result
  "sP" 'cscope-history-backward-file-current-result
  "." 'evil-ex)

(setq evil-leader/leader "," evil-leader/in-all-states t)
(global-evil-leader-mode)

;; @see https://bitbucket.org/lyro/evil/issue/360/possible-evil-search-symbol-forward
;; evil 1.0.8 search word instead of symbol
(setq evil-symbol-word-search t)
;; load undo-tree and ert
(add-to-list 'load-path "~/.emacs.d/site-lisp/evil/lib")
(require 'evil)
(evil-mode 1)

;; {{@see https://github.com/timcharper/evil-surround
(require 'surround)
(global-surround-mode 1)
;; }}

;; ; evil-surround
;; ; @se)
;; ;(require 'surround)
;; (global-surround-mode 1)
;; (evil-mode 1)

;; evil-matchit
(require 'evil-matchit)
(global-evil-matchit-mode 1)

;; evil-nerd-commenter
;; use evil-leader so don't set operator
;; (setq evilnc-hotkey-comment-operator ",,")
;; (require 'evil-nerd-commenter)
;; use evil-leader so don't set default hotkeys
;; (evilnc-default-hotkeys)

(setq evil-want-fine-undo t)

;(evil-set-initial-state 'org-mode 'emacs)
(evil-set-initial-state 'inf-ruby-mode 'emacs)
(evil-set-initial-state 'yari-mode 'emacs)
(evil-set-initial-state 'erc-mode 'emacs)
(evil-set-initial-state 'shell-mode 'emacs)
(evil-set-initial-state 'package-menu-mode 'emacs)
(evil-set-initial-state 'dired-mode 'emacs)
(evil-set-initial-state 'svn-status-mode 'emacs)
(evil-set-initial-state 'eshell-mode 'emacs)
(evil-set-initial-state 'cscope-list-entry-mode 'emacs)
(evil-set-initial-state 'term-mode 'emacs)
(evil-set-initial-state 'telnet-mode 'emacs)
(evil-set-initial-state 'comint-mode 'emacs)

(define-key evil-normal-state-map (kbd "Q") 'kill-this-buffer)

(evil-define-key 'insert cc-mode-map (kbd "\C-n") 'next-line)
(evil-define-key 'insert cc-mode-map (kbd "\C-p") 'previous-line)

;; define key for cscope-list-entry-mode
;;(evil-define-key 'normal cscope-list-entry-keymap (kbd "RET") 'cscope-select-entry-other-window)
(evil-define-key 'motion help-mode-map (kbd "TAB") 'forward-button)

(provide 'init-evil)
